package javango.core;

import javango.core.servers.RequestProcessor.MethodObjectParams;
import javango.http.HttpException;
import javango.http.HttpRequest;

public class SimpleUrl implements Url {

	protected RegUrl regUrl;
	protected String simplePattern;
		
	/**
	 * A {@link Url} that can have the following parameter types
	 * 
	 *  <digits> - any number
	 *  <string> - anything
	 *  
	 * @param factory
	 * @param pattern
	 * @param clazz
	 * @param methodName
	 */
	public SimpleUrl(UrlFactory factory, String pattern, Class<?> clazz, String methodName) {
		regUrl = factory.regUrl(pattern
				.replace("<digits>", "(\\d+)")
				.replace("<string>", "(\\.+)")
				, clazz, methodName);
		
		this.simplePattern = pattern;
	}

	@Override
	public String toString() {
		return "SimpleUrl: '" + simplePattern + "' = '" + regUrl.getPattern() + "'";
	}

	public MethodObjectParams getMethodObjectParams(String url, HttpRequest req)
			throws HttpException {
		return regUrl.getMethodObjectParams(url, req);
	}

	public boolean matches(String url) {
		return regUrl.matches(url);
	}

	
	
}
